//
//  PlaceInfoViewController.m
//  Vacations
//
//  Created by User-23 on 11/1/14.
//  Copyright (c) 2014 TrainingCamp. All rights reserved.
//

#import "PlaceInfoViewController.h"
#import "VacationBook.h"
#import "Vacation.h"
#import "BrokerProtocol.h"
#import "BrokerDelegate.h"


@interface PlaceInfoViewController ()


@property (weak, nonatomic) IBOutlet UIImageView *imageUpLeft;
@property (weak, nonatomic) IBOutlet UIImageView *imageUpRight;
@property (weak, nonatomic) IBOutlet UIImageView *imageDownLeft;
@property (weak, nonatomic) IBOutlet UIImageView *imageDownRight;

@property (weak, nonatomic) IBOutlet UITextView *infoText;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *openDaysLabel;
@property (weak, nonatomic) IBOutlet UILabel *vacationType;

@property id<BrokerProtocol> delegate;
@property VacationBook* obj;

@end


extern const NSInteger kMonasteryIndex;
extern const NSInteger kVillaIndex;
extern const NSInteger kHotelIndex;


@implementation PlaceInfoViewController
// return back to main menu
- (IBAction)backMenuButton:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
    Vacation* newOne = [[VacationBook sheredVacationBook] returnVacation:self.senderButtonTag];
    [self.delegate reviewVacation:newOne];
}

// zapazwa vakanciq ako datata e swobodna :D q stane q ne pri towa e s delegat mai..
- (IBAction)bookVacationButton:(UIButton *)sender {
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"EEEE"];
    NSString* datata =[dateFormatter stringFromDate:[NSDate date]];
    //NSLog(@"%@", datata);
    
    Vacation* newOne = [[VacationBook sheredVacationBook] returnVacation:self.senderButtonTag];
    
    if ([self.delegate isVacation:newOne openForDay:datata]) {
        //NSLog(@"rygni nai nakraq be");
        [[[UIAlertView alloc] initWithTitle:@"zapiswane" message:[NSString stringWithFormat: @"%@ vi zapisa i vi ochakwa",newOne.name] delegate:nil cancelButtonTitle:@"Ztwori prozoreca che duha" otherButtonTitles:nil, nil]show];
    }else{
        //NSLog(@"neiskam");
        [[[UIAlertView alloc] initWithTitle:@"zapiswane" message:[NSString stringWithFormat: @"%@ \n\"dnes ne bacame\" :)",newOne.name] delegate:nil cancelButtonTitle:@"Ztwori prozoreca che duha" otherButtonTitles:nil, nil]show];
    }
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationItem.hidesBackButton = YES;
    
    // initialize object and get some values from it for view
    Vacation* vac1 = [[VacationBook sheredVacationBook] returnVacation:self.senderButtonTag];
    self.vacationType.text = self.navigationItem.title;
    
    self.infoText.text = vac1.info;
    self.priceLabel.text = [NSString stringWithFormat:@"Price:%@", vac1.price];
    self.openDaysLabel.text = [NSString stringWithFormat:@"Open:%@", vac1.openDays];
    
    
    // add pictures to depent what it choose and info too 
    if (self.senderButtonTag == kMonasteryIndex) {
        self.imageUpLeft.image = [UIImage imageNamed:@"monastery01.jpg"];
        self.imageUpRight.image = [UIImage imageNamed:@"monastery2.jpg"];
        self.imageDownLeft.image = [UIImage imageNamed:@"monastery3.jpg"];
        self.imageDownRight.image = [UIImage imageNamed:@"monastery4.JPG"];
    }

    if (self.senderButtonTag == kVillaIndex) {
        self.imageUpLeft.image = [UIImage imageNamed:@"villa1.jpeg"];
        self.imageUpRight.image = [UIImage imageNamed:@"villa2.jpeg"];
        self.imageDownLeft.image = [UIImage imageNamed:@"villa3.jpg"];
        self.imageDownRight.image = [UIImage imageNamed:@"villa4.jpeg"];
    }

    if (self.senderButtonTag == kHotelIndex) {
        self.imageUpLeft.image = [UIImage imageNamed:@"hotel1.jpeg"];
        self.imageUpRight.image = [UIImage imageNamed:@"hotel2.jpeg"];
        self.imageDownLeft.image = [UIImage imageNamed:@"hotel3.jpeg"];
        self.imageDownRight.image = [UIImage imageNamed:@"hotel4.jpeg"];
    }
}



- (void)viewDidLoad {
    // kogato se ignorira towa spira da generira nova vakanciq wseki pyt kogato se wliza w novo view 
    //[super viewDidLoad];
    
    // ako towa e cqlata prostotiq s delegiraneto to si mislq che mai sym q razbral
    // moje da pospa malko ( ama malko samo :) )
    self.delegate = [[BrokerDelegate alloc] init];
    self.obj = [VacationBook sheredVacationBook];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
